package com.ruoyi.ldzlsc.config;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.Date;

/**
 * WebSocket消息类
 * 
 * @author ldzl
 * @date 2025-01-23
 */
public class WebSocketMessage<T> {
    
    /**
     * 消息类型
     */
    private String type;
    
    /**
     * 消息内容
     */
    private String message;
    
    /**
     * 消息数据
     */
    private T data;
    
    /**
     * 时间戳
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date timestamp;

    public WebSocketMessage() {
        this.timestamp = new Date();
    }

    public WebSocketMessage(String type, String message, T data) {
        this.type = type;
        this.message = message;
        this.data = data;
        this.timestamp = new Date();
    }

    // Getters and Setters
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String toString() {
        return "WebSocketMessage{" +
                "type='" + type + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                ", timestamp=" + timestamp +
                '}';
    }
}
